package com.wantong.jianpu.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.view.TimePickerView;
import com.wantong.jianpu.BR;
import com.wantong.jianpu.R;
import com.wantong.jianpu.base.BaseXActivity;
import com.wantong.jianpu.databinding.ActivityTourSignBinding;
import com.wantong.jianpu.viewmodels.TourSignViewModel;

import java.util.Calendar;

/**
 * 签名
 */
public class TourSignActivity extends BaseXActivity<ActivityTourSignBinding, TourSignViewModel> {
    TimePickerView popup;
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_tour_sign;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setToolbar(binding.baseToolBar);
        viewModel.id=getIntent().getExtras().getString("id");
        binding.timeCtv.setOnClickListener(v -> {
            showDatePicker();
        });
    }

    /**
     * 日期选择器
     */
    private void showDatePicker() {
        Calendar cal = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        cal.set(cal2.get(Calendar.YEAR) - 5, 0, 1);

        if (popup == null) {
            popup = new TimePickerBuilder(TourSignActivity.this, (date, v) -> {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                String month = (calendar.get(Calendar.MONTH) + 1) + "";
                month = month.length() > 1 ? month : "0" + month;
                viewModel.time.setValue(calendar.get(Calendar.YEAR) + "-" + month+"-"+calendar.get(Calendar.DAY_OF_MONTH)+" "+calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND));
            })
                    .setType(new boolean[]{true, true, true, true, true, true})
                    .setTitleText("选择时间")
                    .setRangDate(cal, cal2)
                    .build();
        }
        popup.setDate(Calendar.getInstance());
        popup.show();

    }
}